#include "settings.h"
#include <QApplication>

//---------------------------------------------------------
Settings::Settings (const QString& org, const QString& app, QObject* obj)
    : QSettings (org, app, obj)
{
    read ();
}
//--------------------
Settings::~Settings ()
{
    write ();
}
//--------------------
void Settings::read ()
{
    beginGroup ("General");
    m_appIconPath = value ("AppIconPath", APP_ICON_PATH).toString ();
    m_magnumIconPath = value ("MagnumIconPath", MAGNUM_ICON_PATH).toString ();
    m_alertIconPath = value ("AlertIconPath", ALERT_ICON_PATH).toString ();
    m_newIconPath = value ("NewIconPath", NEW_ICON_PATH).toString ();
    m_appTitle = value ("AppTitle", APP_TITLE).toString ();
    m_pub = value ("Pub", PUB).toString ();
    endGroup ();

    beginGroup ("Colors");
    m_systrayProgressColor = value ("Progress", SYSTRAY_PROGRESS_COLOR).value<QColor> ();
    m_systrayBackgroundColor = value ("Background", SYSTRAY_BACKGROUND_COLOR).value<QColor> ();
    m_systrayFontColor = value ("Font", SYSTRAY_FONT_COLOR).value<QColor> ();
    endGroup ();

    beginGroup ("Messages");
    m_standardToolTip = value ("StandardToolTip", STANDARD_TOOLTIP).toString ();
    m_tooltipsTitle = value ("ToolTipTitle", TOOLTIPS_TITLE).toString ();
    m_messageTitle = value ("MessageTitle", MESSAGE_TITLE).toString ();
    endGroup ();

    beginGroup ("Options");
    m_isBlinking = value ("Blink", false).toBool ();
    m_messageDuration = value ("MessageDuration", MESSAGE_DURATION).toInt ();
    endGroup ();

}
//---------------------
void Settings::write ()
{
    beginGroup ("General");
    setValue ("AppTitle", m_appTitle);
    setValue ("AppIconPath", m_appIconPath);
    setValue ("MagnumIconPath", m_magnumIconPath);
    setValue ("AlertIconPath", m_alertIconPath);
    setValue ("NewIconPath", m_newIconPath);
    setValue ("Pub", m_pub);
    endGroup ();

    beginGroup ("Colors");
    setValue ("Progress", m_systrayProgressColor);
    setValue ("Background", m_systrayBackgroundColor);
    setValue ("Font", m_systrayFontColor);
    endGroup ();

    beginGroup ("Messages");
    setValue ("StandardToolTip", m_standardToolTip);
    setValue ("ToolTipTitle", m_tooltipsTitle);
    setValue ("MessageTitle", m_messageTitle);
    endGroup ();

    beginGroup ("Options");
    setValue ("Blink", m_isBlinking);
    setValue ("MessageDuration", m_messageDuration);
    endGroup ();
}

